/*
 * @Author: 晟松
 * @Date: 2021-12-07 20:36:00
 * @LastEditors: 晟松
 * @LastEditTime: 2022-01-23 15:37:53
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\model\Community.js
 * @Description: 居委会的model
 */
import Sequelize from "sequelize";
import { isValidateEnum, isProvince } from "@main/util/ValidateUtil";
import { ParamError } from "../common/CommonError";
import enums from "@main/config/enums";

export const modelName = "community";

const DataTypes = Sequelize.DataTypes;

export const attributes = {
    identity: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (val != enums["identity"]["community"]) {
                    throw new ParamError(`identity community: ${val}值错误`);
                }
            },
        },
    },
    userName: {
        type: DataTypes.STRING,
    },
    avatar: {
        type: DataTypes.STRING,
    },
    gender: {
        type: DataTypes.INTEGER,
        validate: {
            check(val) {
                if (!isValidateEnum(val, "gender")) {
                    throw new ParamError(`gender: ${val}值错误`);
                }
            },
        },
    },
    introduction: DataTypes.STRING,
    province: {
        type: DataTypes.STRING,
        validate: {
            check(val) {
                if (!isProvince(val)) {
                    throw new ParamError(`省不存在`);
                }
            },
        },
    },
    city: DataTypes.STRING,
    region: DataTypes.STRING,
    communityName: {
        type: DataTypes.STRING,
    },
    // 这两个是关于区块链的一个记录，主要是记录其中的交易hash和块hash，通过这两个hash就可从区块链中获取到对应的信息
    transactionHash: DataTypes.STRING,
    blockHash: DataTypes.STRING,
};

export const options = {
    // tableName: "t_user_reference",
};
